//package com.yu8home.opcua;
//
//import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
//import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription;
//import org.eclipse.milo.opcua.sdk.server.api.MonitoredItem;
//import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
//import org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode;
//import org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest;
//import org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemNotification;
//import org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters;
//import org.eclipse.milo.opcua.stack.core.types.structured.NotificationMessage;
//import org.eclipse.milo.opcua.stack.core.types.structures.MonitoringParameters;
//import org.eclipse.milo.opcua.stack.core.types.structures.MonitoredItemCreateRequest;
//import org.eclipse.milo.opcua.stack.core.types.structures.MonitoredItemNotification;
//import org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringKind;
//import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
//
//import java.util.concurrent.ExecutionException;
//import java.util.function.Consumer;
//
//public class SubscribeAlarmsAndEventsExample {
//
//    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        OpcUaClient client = null; // 初始化你的OPC UA客户端
//
//        // 创建订阅
//        UaSubscription subscription = client.getSubscriptionManager()
//                .createSubscription(new SubscriptionParameters()
//                        .setPublishingInterval(500.0) // 设置发布间隔，单位毫秒
//                        .setLifetimeCount(10)
//                        .setMaxKeepAliveCount(3))
//                .get();
//
//        // 监听事件的节点ID，例如：事件视图的EventView节点
//        NodeId eventViewNodeId = NodeId.parse("ns=0;i=2000");
//
//        // 创建监控参数
//        MonitoringParameters monitoringParameters = new MonitoringParameters(
//                UInteger.valueOf(subscription.nextSequenceNumber()),
//                subscription.getPublishingInterval(),
//                null,
//                UInteger.ONE,
//                MonitoringMode.Reporting);
//
//        // 创建监控项请求
//        MonitoredItemCreateRequest monitoredItemCreateRequest = new MonitoredItemCreateRequest(
//                MonitoringKind.Event,
//                eventViewNodeId,
//                monitoringParameters);
//
//        // 创建监控项并订阅事件
//        subscription.createMonitoredItems(
//                new MonitoredItemCreateRequest[]{monitoredItemCreateRequest},
//                new Consumer<MonitoredItemCreateResponse>() {
//                    @Override
//                    public void accept(MonitoredItemCreateResponse monitoredItemCreateResponse) {
//                        // 获取监控项的结果
//                        MonitoredItem monitoredItem = monitoredItemCreateResponse.getMonitoredItem();
//
//                        // 添加事件通知的回调
//                        monitoredItem.setValueConsumer(new Consumer<MonitoredItemNotification>() {
//                            @Override
//                            public void accept(MonitoredItemNotification monitoredItemNotification) {
//
//                                NotificationMessage a = new NotificationMessage();
//                                a.
//
//
//
//                                // 处理事件通知
//                                for (MonitoredItemNotification item : monitoredItemNotification.getValues()) {
//
//                                    item.
//
//                                    System.out.println("Event Notification: " + item);
//                                }
//                            }
//                        });
//                    }
//                });
//
//    }
//}
